<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div>
        <span>公告</span>
        <span>规则</span>
        <span>论坛</span>
    </div>
    <div class="content"></div>
    <script>
        var spans=document.getElementsByTagName("span");//集合
        var content=document.querySelector(".content");
        var arrs=["这是公告","这是规则","这是论坛"];
        // var prev;
        for(let i=0;i<spans.length;i++){
            spans[i].onclick=function(){
                // if(prev){
                //     prev.style.borderBottom="";
                // }
                
                //循环让每一个span去掉下变框
                for(var j=0;j<spans.length;j++){
                    spans[j].style.borderBottom="";
                }

                content.innerHTML=arrs[i];
                this.style.borderBottom="1px solid red";
                prev=this;
            };
        }

    </script>
</body>
</html>